package solutions.leetcode.normal;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/unique-binary-search-trees/">96. 不同的二叉搜索树</a>
 */
public class Solution96 extends BaseSolution {

    public int numTrees(int n) {
        int[] rst = new int[n + 1];
        rst[1] = 1;
        for (int i = 2; i <= n; i++) {
            int r = 0;
            for (int j = 1; j < i - 1; j++) {
                r += rst[j] * rst[i - 1 - j];
            }
            rst[i] = r + 2 * rst[i - 1];
        }
        return rst[n];
    }

    public static void main(String[] args) {
        Solution96 solution = new Solution96();
        System.out.println(solution.numTrees(1));
    }
}